//
//  ShowMessageViewController.m
//  NLProjectFrameworkDemo
//
//  Created by iosdeveloper on 2020/4/29.
//  Copyright © 2020 yj_zhang. All rights reserved.
//

#import "ShowMessageViewController.h"
#import "CommonHeader.h"

static NSInteger btnTag=999;
@interface ShowMessageViewController ()
@property(nonatomic,strong)UIView*bgView;
@end

@implementation ShowMessageViewController
-(instancetype)initWithArr:(NSArray *)titleArr{
    self=[super init];
    if (self) {
        [self setUpView:titleArr];
    }
    return self;
}



- (void)viewDidLoad {
    [super viewDidLoad];
   
   
}

-(void)setUpView:(NSArray*)titleArr{
    
    UIView*blackView = [[UIView alloc]initWithFrame:self.view.bounds];
    blackView.backgroundColor =[UIColor jk_colorWithHexString:@"#FF14181A"];
    blackView.alpha=0.8;
    [self.view addSubview:blackView];
//    UITapGestureRecognizer*tapVC =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissFromParentVC)];
//    [blackView addGestureRecognizer:tapVC];
    
    
    
    UIView*bgView = [UIView new];
    bgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bgView];
    CGFloat bgWidth =adaptWidth750(280*2);
    CGFloat bgHeight =adaptWidth750(178*2);
    CGSize bgSize =CGSizeMake(bgWidth, bgHeight);
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(blackView);
        make.size.mas_equalTo(bgSize);
    }];
    ViewRadius(bgView, 16);
    
    
    
    UILabel*titleLabel = [UILabel new];
    titleLabel.text=@"提示";
    titleLabel.font =KIMFontMedium(17);
    titleLabel.textColor=[UIColor jk_colorWithHexString:@"#FF3E464C"];
    titleLabel.textAlignment=NSTextAlignmentCenter;
    titleLabel.numberOfLines=1;
    [bgView addSubview:titleLabel];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(adaptWidth750(48));
        make.left.width.equalTo(bgView);
    }];
    
    UILabel*messageabel = [UILabel new];
    self.messageLabel=messageabel;
    messageabel.font =KIMFontRegularSize(15);
    messageabel.textColor=[UIColor jk_colorWithHexString:@"#FFA1A6AB"];
    messageabel.textAlignment=NSTextAlignmentCenter;
    messageabel.numberOfLines=0;
    [bgView addSubview:messageabel];
    CGFloat leftMargin=adaptWidth750(40);
    [messageabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLabel.mas_bottom).offset(adaptWidth750(20));
        make.left.mas_equalTo(leftMargin);
        make.right.mas_equalTo(-leftMargin);
    }];
    

    NSArray*bgColorArr=@[[UIColor whiteColor],KAppMainColor];
     NSArray*titleColorArr=@[[UIColor jk_colorWithHexString:@"#FF3E464C"],[UIColor whiteColor]];
    NSArray*connerLine=@[@(1),@(0)];
    
    CGFloat btnLeftMargin =adaptWidth750(40);
    CGFloat btnMiddleMargin=adaptWidth750(20);
    

    CGFloat loginBtnWidth=(bgWidth-btnLeftMargin*2-btnMiddleMargin)/2;
    CGFloat loginBtnHeight=adaptWidth750(40*2);


    CGSize btnSize =CGSizeMake(loginBtnWidth, loginBtnHeight);
    for (int i=0; i<titleArr.count; i++) {
        UIButton*loginBtn=[UIButton new];
        [loginBtn setTitle:titleArr[i] forState:UIControlStateNormal];
        loginBtn.tag=btnTag+i;
        [loginBtn jk_setBackgroundColor:bgColorArr[i] forState:UIControlStateNormal];
        [loginBtn setTitleColor:titleColorArr[i] forState:UIControlStateNormal];
        loginBtn.titleLabel.font = KIMFontRegularSize(15);
        [bgView addSubview:loginBtn];
      
        if (titleArr.count==2) {
            [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(btnLeftMargin+(loginBtnWidth+btnMiddleMargin)*i);
                make.size.mas_equalTo(btnSize);
                make.bottom.mas_equalTo(-btnLeftMargin);
            }];
            
            CGFloat lineWidth=[connerLine[i]floatValue];
            ViewBorderRadius(loginBtn, loginBtnHeight/2.0,lineWidth, [UIColor jk_colorWithHexString:@"#FFCBCBCB"]);
        }else{
            [loginBtn jk_setBackgroundColor:KAppMainColor forState:UIControlStateNormal];
            [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(bgView);
                make.size.mas_equalTo(btnSize);
                make.bottom.mas_equalTo(-btnLeftMargin);
            }];
            
            ViewBorderRadius(loginBtn, loginBtnHeight/2.0,0, [UIColor jk_colorWithHexString:@"#FFCBCBCB"]);
        }
       
        
        if (i==0) {
            [loginBtn addTarget:self action:@selector(exitActionBlock:) forControlEvents:UIControlEventTouchUpInside];
        }else{
            [loginBtn addTarget:self action:@selector(ReLoginActionBlock:) forControlEvents:UIControlEventTouchUpInside];
        }
        
       
    }

}
//左边按钮事件
-(void)exitActionBlock:(UIButton*)sender{
    !self.cancleBlock?:self.cancleBlock();
}


//右边按钮事件
-(void)ReLoginActionBlock:(UIButton*)sender{
  !self.ensureBlock?:self.ensureBlock();
}


-(void)showCurrentVC:(UIViewController*)baseVC{
    WS(weakSelf);
    [baseVC addChildViewController:self];
    [baseVC.view addSubview:self.view];
      weakSelf.view.frame=CGRectMake(0, IMSCREEN_HEIGHT, IMSCREEN_HEIGHT, IMSCREEN_HEIGHT);
    [UIView animateWithDuration:.0 animations:^{
        weakSelf.view.frame=CGRectMake(0, 0, IMSCREEN_HEIGHT, IMSCREEN_HEIGHT);
    }];
}

-(void)dismissFromParentVC{
    WS(weakSelf);
//    weakSelf.view.frame=CGRectMake(0, 0, IMSCREEN_HEIGHT, IMSCREEN_HEIGHT);
//    [UIView animateWithDuration:.2 animations:^{
//        weakSelf.view.frame=CGRectMake(0, IMSCREEN_HEIGHT, IMSCREEN_HEIGHT, IMSCREEN_HEIGHT);
//    } completion:^(BOOL finished) {
        [weakSelf.view removeFromSuperview];
        [weakSelf removeFromParentViewController];
//    }];
}





/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
